package com.qf.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Value("${rabbit.exchange}")
    private String exchangeName;

    @Value("${rabbit.queue}")
    private String queueName;

    @Value("${rabbit.bind}")
    private String bind;

    // 创建交换机
    @Bean
    public TopicExchange topicExchange(){
        return (TopicExchange) ExchangeBuilder.topicExchange(exchangeName).build();
    }

    // 创建队列
    @Bean
    public Queue queue(){
        return QueueBuilder.durable(queueName).build();
    }

    // 绑定到一起
    @Bean
    public Binding binding(Queue queue,TopicExchange topicExchange){
        return BindingBuilder.bind(queue).to(topicExchange).with(bind);
    }
}
